<template>
  <a-modal
    width="600px"
    :footer="null"
    :maskClosable="false"
    :closable="false"
    :mask="false"
    v-model:open="modalShow"
    :wrap-style="{ overflow: 'hidden' }"
  >
    <template #title>
      <modalTitle @close="close" :title="'高空抛物识别'"></modalTitle>
    </template>
    <div style="padding: 0 10px 10px 10px">
      <div class="content">
        <div style="display: flex; color: #ffffff99">
          <div style="font-size: 13px">{{ data }}</div>
          <div style="font-size: 13px; margin-left: 20px">现场指挥官：{{ spl.commander }}</div>
          <div style="margin-left: 20px; font-size: 13px">联系方式：{{ spl.commander_phone }}</div>
        </div>
        <div style="display: flex; justify-content: space-between; margin-top: 10px">
          <div style="background: linear-gradient(180deg, rgba(30, 121, 88, 0) 0%, #1e6579 100%); width: 48%; text-align: center; padding: 10px 0">
            <div style="color: #d5f2ff; font-size: 13px">本日检测高空抛物数</div>
            <div style="font-weight: bold">0次</div>
          </div>
          <div style="background: linear-gradient(rgba(30, 121, 88, 0) 0%, #1e6579 100%); text-align: center; width: 48%; padding: 10px 0">
            <div style="color: #d5f2ff; font-size: 13px">本月检测高空抛物数</div>
            <div style="font-weight: bold">0次</div>
          </div>
        </div>
        <div style="margin: 10px 0; font-weight: bold">实时监控</div>
        <div class="video-container" v-if="modalShow">
          <video v-if="isOK" ref="videoElementgk" class="video-js vjs-big-play-centered" autoplay controls></video>
          <div v-else class="jkbox-err">连接失败</div>
        </div>
        <!-- <div style="margin: 10px 0; font-weight: bold">照片抓拍</div>
        <div style="display: flex; justify-content: space-between">
          <div style="width: 31%; height: 120px; background-color: #fff"></div>
          <div style="width: 31%; height: 120px; background-color: #fff"></div>
          <div style="width: 31%; height: 120px; background-color: #fff"></div>
        </div> -->
      </div>
    </div>
  </a-modal>
</template>
<script setup>
import { reactive, ref } from "vue"
import modalTitle from "../../modalTitle.vue"
import axios from "axios"
import videojs from "video.js"
import "video.js/dist/video-js.css"
const modalShow = ref(false)

const close = () => {
  modalShow.value = false
  if (player.value) {
    player.value.dispose()
  }
}

const data = ref("")
const device_no = ref("")
// 视频流
const spl = ref("")
const player = ref(null)
const videoElementgk = ref(null)
const isOK = ref(true)

const show = (e) => {
  data.value = e.data
  device_no.value = e.device_no
  modalShow.value = true
  isOK.value = true
  getSp()
}
defineExpose({ show, close })

const play = (url) => {
  player.value = videojs(videoElementgk.value, {
    autoplay: true,
    muted: true,
    controls: true,
    sources: [
      {
        src: url,
        type: "application/x-mpegURL"
      }
    ]
  })

  player.value.on("error", () => {
    isOK.value = false
  })
}

const getSp = async () => {
  axios({
    method: "post",
    url: "http://ylz.chuangxing.ren/api/index/ics_test",
    data: {
      cameraIndexCode: device_no.value
    }
  }).then((res) => {
    spl.value = res.data.data.data
    play(spl.value.url)
  })
}
</script>
<style scoped>
.content {
  /* background: #4DDECF1A; */
  padding: 0 0 10px 0;
  /* border: 1px solid #4DDECF33; */
  /* border-radius: 10px; */
  color: #ffffff;
}

.btn {
  background: linear-gradient(180deg, rgba(0, 36, 42, 0.5) 0%, rgba(0, 67, 78, 0.5) 100%);
  border: 1px solid #57ffff;
  color: #ffffff;
  font-size: 10px;
  padding: 5px 20px;
  border-radius: 99px;
  cursor: pointer;
  margin-bottom: 10px;
}

.jkbox-err {
  position: absolute;
  width: 100%;
  height: 100%;
  color: #fff;
  top: 0;
  left: 0;
  text-align: center;
  line-height: 250px;
  background: rgba(0, 0, 0);
  z-index: 99999;
}

.video-container {
  width: 100%;
  height: 250px;
  margin: 0 auto;
  background: #000;
  position: relative;
}

/* 覆盖默认样式 */
:deep(.video-js) {
  width: 100%;
  height: 250px;
  position: relative;
}

:deep(.video-js .vjs-tech) {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

:deep(.vjs-big-play-button) {
  background-color: rgba(66, 184, 131, 0.7);
  border: none;
  width: 80px;
  height: 80px;
  line-height: 80px;
  border-radius: 50%;
  margin-left: -40px;
  margin-top: -40px;
}
</style>
